﻿#region

using System.Drawing;
using System.IO;
using System.Windows.Forms;
using PicSizer.Program.FileIO;
using static PicSizer.Program.Static.PicUnit;

#endregion

namespace PicSizer.Program.Window.Assemble
{
    public class PicListViewItem : ListViewItem
    {
        /// <summary>
        /// 文件大小(单位:KB)
        /// </summary>
        private long _size;

        /// <summary>
        /// 图片状态
        /// </summary>
        private PicItemState _state;

        private string _message = null;

        /// <summary>
        /// 文件名
        /// </summary>
        public string FileName
        {
            get => this.SubItems[0].Text;
            private set => this.SubItems[0].Text = value;
        }

        /// <summary>
        /// 完整路径
        /// </summary>
        public string FullPath
        {
            get => this.SubItems[1].Text;
            private set => this.SubItems[1].Text = value;
        }

        /// <summary>
        /// 文件大小
        /// </summary>
        public long Size
        {
            get => this._size;
            private set
            {
                this._size = value;
                this.SubItems[2].Text = FileProc.FileSizeToString(this._size);
            }
        }

        /// <summary>
        /// 其他信息
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public PicItemState State
        {
            get => this._state;
            set
            {
                this._state = value;
                switch (value)
                {
                    case PicItemState.Waiting:
                        this.SubItems[3].Text = "待压缩";
                        this.SubItems[3].ForeColor = Color.Black;
                        break;
                    case PicItemState.Compression:
                        this.SubItems[3].Text = "压缩中";
                        this.SubItems[3].ForeColor = Color.Blue;
                        break;
                    case PicItemState.Success:
                        this.SubItems[3].Text = "完成";
                        this.SubItems[3].ForeColor = Color.Green;
                        break;
                    case PicItemState.OutOfLimit:
                        this.SubItems[3].Text = "超出";
                        this.SubItems[3].ForeColor = Color.Orange;
                        break;
                    case PicItemState.Error:
                        this.SubItems[3].Text = "错误";
                        this.SubItems[3].ForeColor = Color.Red;
                        break;
                }
            }
        }

        public PicListViewItem(string path)
        {
            for (int i = 0; i < 3; i++)
                this.SubItems.Add(new ListViewSubItem());

            this.UseItemStyleForSubItems = false;
            FileInfo fileInfo = new FileInfo(path);
            this.FullPath = fileInfo.FullName;
            this.FileName = fileInfo.Name;
            this.Size = fileInfo.Length >> 10; //单位:KB
            this.State = PicItemState.Waiting;
        }
    }
}